#ifndef CMF_H
#define CMF_H

#include <iostream>


template <typename TDV, typename TV, typename TDM, typename TM> 
TV findCM(uint N, TDV *dvp, TV *vp, TDM *dmp, TM *mp){
	
	int ofsv =  sizeof(*dvp);
	int ofsm =  sizeof(*dmp);

	TM M(0);
	TV V; V*=0;
	
	for (uint i=0; i<N; i++) {
		
		V += (*vp)*(*mp);
		M += *mp;
		
		vp = (TV*)((char*)vp+ofsv);
		mp = (TM*)((char*)mp+ofsm);
	
	}
	
	V/=M;
	
	return V;
}


#endif